package com.xw.controller.api.sysapi;

import com.aliyuncs.exceptions.ClientException;
import com.xw.common.Const;
import com.xw.service.sysconfig.VerificationCodeService;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Map;

@Controller
@RequestMapping("/api/verificationCode/")
@Scope("prototype")
public class ApiVerificationCodeController {


    @Resource
    private VerificationCodeService verificationCodeService;

    /**
     * 发送验证码
     * @param phone    手机号
     * @return
     */
    @RequestMapping(value = "sendVerificationCode", method = RequestMethod.POST)
    @ResponseBody
    public Object sendVerificationCode(HttpServletRequest request, String phone) throws ParseException, ClientException {
        //验证web 是否是该项目
        if (!AppUtil.checkWeb(request)) {
            return JsonData.fail(Const.CHECK_WEB_ERROR);
        }
        Map map = verificationCodeService.sendVerificationCode(phone);
        return map;
    }

}
